#include "Application.h"
#include "ResourceManager.h"
#include "SceneManager.h"
#include "FileManager.h"
#include "InputManager.h"
#include "FrameBuffer.h"
#include "ScreenResolution.h"
#include "Collision.h"
#include "Application.h"
#include "MainMenu.h"

Application* Application::s_instance = NULL;

Application::Application(void)
{
}

Application::~Application(void)
{
}

Application* Application::GetInstance()
{
	if (s_instance == NULL)
	{
		s_instance = new Application();
	}
	return s_instance;
}

void Application::DestroyInstance()
{
	if (s_instance != NULL)
	{
		SAFE_DEL(s_instance);
	}
}

void Application::Init()
{
	ResourceManager *resourceManager = NULL;
	FileManager *fileManager = NULL;

	fileManager = FileManager::GetInstance();
	#ifdef _WIN32
	fileManager->Init("../Resources/");
	#endif
	#ifdef _ANDROID
	fileManager->Init("sdcard/Resources/");
	#endif

	resourceManager = ResourceManager::GetInstance();
	resourceManager->Init("Managers/ResourceManager.txt");

	m_currentState = Logo::GetInstance();
	m_currentState->Init();
}

void Application::Update()
{
	if (InputManager::GetInstance()->IsKeyDown(66))
	{
		SwitchState(MainMenu::GetInstance());
	}

	m_currentState->Update();
}

void Application::Draw()
{
	m_currentState->Draw();
}

void Application::Destroy()
{
	m_currentState->Destroy();

	ResourceManager::Destroy();
	FileManager::Destroy();
	InputManager::Destroy();
	ScreenResolution::Destroy();

	Logo::DestroyInstance();
	MainMenu::DestroyInstance();
}

void Application::SwitchState(State *newState)
{
	m_currentState->Destroy();
	newState->Init();
	m_currentState = newState;
}